
/**
 * @brief  bsp_tim1_pwm.c/h
 * @param  定时器1的PWM通道控制
 * @author 颜福兵
 * @date   2022/9/5
 * 
 **/

#include "bsp_tim1_pwm.h"
#include "hrtim.h"

/**
 * @brief TIM1初始化
 * @param  
 */
void HRtim1_init(void)
{
	
HAL_HRTIM_WaveformOutputStart(&hhrtim1, HRTIM_OUTPUT_TA1|HRTIM_OUTPUT_TA2); //通道打开
HAL_HRTIM_WaveformOutputStart(&hhrtim1, HRTIM_OUTPUT_TE1|HRTIM_OUTPUT_TE2); //通道打开
HAL_HRTIM_WaveformCountStart(&hhrtim1,  HRTIM_TIMERID_TIMER_A | HRTIM_TIMERID_TIMER_E);  //打开子定时器A,B
//__HAL_HRTIM_TIMER_ENABLE_IT(&hhrtim1,HRTIM_TIMERINDEX_TIMER_A,HRTIM_TIM_IT_REP);
	setHRTim1_Pwm_outputs(10, 0, 10);    //设置初始化的比较值
}

/**
 * @brief 控制互补PWM的输出
 * @param ch1 
 * @param ch2 
 * @param ch3 
 */
void setHRTim1_Pwm_outputs(uint32_t cha, uint32_t chb,uint32_t che)
{
	HRTIM1->sTimerxRegs[0].CMP1xR=cha;
	HRTIM1->sTimerxRegs[4].CMP1xR=che;
//hhrtim1.Instance->sTimerxRegs[0].CMP1xR = cha;//通过修改比较值CMP，从而修改占空比
//hhrtim1.Instance->sTimerxRegs[4].CMP1xR = cha;//通过修改比较值CMP，从而修改占空比
}

 /**
  * @brief 通道4比较输出
  * @param ch4 
  */
 void setHRTim1_Pwm_nooutput(float ch4)
{
//	uint32_t ccr4;
	//ccr4 = (uint32_t)fp32_constrain(ch4, 0, 100) * 42;
	//__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_4, ccr4);
}

  /**
   * @brief 通道4互补输出使能
   * @param isEnable 
   */
  void HRtimer1Channel4ITenable(uint8_t isEnable)
{
	if (isEnable)
	{
	///	HAL_TIM_PWM_Start_IT(&htim1, TIM_CHANNEL_4);
	//	HAL_TIM_Base_Start_IT(&htim1);
	}
	else
	{
	//	HAL_TIM_PWM_Stop_IT(&htim1, TIM_CHANNEL_4);
	//	HAL_TIM_Base_Stop_IT(&htim1);
	}
}


////////////////////// end of the file 
